import { WereWolfMorningPhase } from "@/werewolf/phases/morning";
import { WereWolfPhaseView } from "@/werewolf/phaseView";
import { WereWolfStatus } from "@/werewolf/player";
import { ScriptRunner } from "@sapi-game/Runner/scriptRunner";
import { CampViewTools } from "./tools";

export class MorningCampView extends WereWolfPhaseView<WereWolfMorningPhase> {
    override async runPhaseView(r: ScriptRunner): Promise<void> {
        CampViewTools.resetStructure();
        await r.wait(100);
        this.players.title(`§a§l第§e${this.context.day}§a天`);
        await r.wait(80);
        await this.news(r);
        await r.wait(80);
        this.state.next();
    }

    async news(r: ScriptRunner) {
        this.players.title("§e⭐§a晨报§e⭐", "§b§l昨天...");
        await r.wait(15);
        this.players.forEach((p) =>
            p.player.onScreenDisplay.updateSubtitle("§b§l昨天..")
        );
        await r.wait(15);
        this.players.forEach((p) =>
            p.player.onScreenDisplay.updateSubtitle("§b§l昨天.")
        );
        await r.wait(40);
        //死亡播报
        const deadPlayers = this.players.filter(
            (p) => p.status == WereWolfStatus.justDead
        );
        let text = "";
        if (deadPlayers.length) {
            text =
                "§l§0[§7死亡§0]§4" + deadPlayers.map((p) => p.name).join(",");
        } else {
            text = "§a§l平安夜";
        }
        this.players.title("§e⭐§a晨报§e⭐", text);
    }
}
